const express = require("express");
const app = express();
app.use(express.json());// 如果请求体的数据格式为application/json会将其放置至req.body中
app.use(express.urlencoded());// 如果请求体的数据格式为application/x-www-form-urlencoded会将其放置到req.body中
// http://zhangpeiyue.com:8091/info/100/200?a=10&b=20
app.get("/info/:id/:type",(req,res)=>{
	console.log(req.method);// 查看请求方式
	console.log(req.url);// /info?a=10&b=20
	console.log(req.query);// {a:'10',b:'20'}
	console.log(req.params);// {id:'100',type:'200'}
	console.log(req.headers);// 请求头
	console.log(req.headers.host);// zhangpeiyue.com:8091
	console.log(req.get("host"));
	res.send("over");
});

app.post("/info",(req,res)=>{
	// 获取请求体数据
	console.log(req.body);// {username: '12121212'}
	res.send("post->info")
});
app.listen(8091,()=>{
	console.log("success");
})